﻿using System.ComponentModel.Composition;
using System.Windows.Controls;
using ScrumFactory.Composition.View;
using System.Windows.Documents;


namespace ScrumFactory.Reports {
    
    /// <summary>    
    /// Interaction logic for DeliveryReport.xaml
    /// </summary>
    [Export]
    public partial class DefaultReport : UserControl, View.IReportView {

        private object model;

        //private System.Windows.Documents.FlowDocument Document;

        public DefaultReport() {
            InitializeComponent();
        }
       
        [Import(typeof(ViewModel.DefaultReportViewModel))]
        public object Model {
            get {
                return this.model;
            }
            set {
                this.model = value;
                this.DataContext = value;
            }
        }

        public FlowDocument Report {
            get {
                return documentReader.Document;
            }
        }

        public void SetReportDocument(string xaml) {
            if (xaml == null)
                documentReader.Document = null;
            else
                documentReader.Document = System.Windows.Markup.XamlReader.Parse(xaml) as System.Windows.Documents.FlowDocument;            
        }

        public void SetElementViewModel(string name, object model) {
            if (documentReader.Document == null)
                return;
            IView element = documentReader.Document.FindName(name) as IView;
            if (element == null)
                return;
            element.Model = model;
        }

        public void Print() {
            documentReader.Print();
        }
    }
}
